package cn.zl.ymcc.utils;

import java.util.regex.Pattern;
import java.util.regex.Matcher;

public class PhoneValidator {
    
    // 基础正则：严格的11位手机号
    private static final String BASIC_PATTERN = "^1[3-9]\\d{9}$";
    
    // 高级正则：支持带分隔符和国际区号
    private static final String ADVANCED_PATTERN = "^(?:\\+?86)?1[3-9]\\d[- ]?\\d{4}[- ]?\\d{4}$";
    
    public static boolean validateBasic(String phone) {
        return Pattern.matches(BASIC_PATTERN, phone);
    }
    
    public static boolean validateAdvanced(String phone) {
        // 首先检查基础格式
        if (!Pattern.matches(ADVANCED_PATTERN, phone)) {
            return false;
        }
        
        // 提取纯数字进行严格验证
        String cleanPhone = phone.replaceAll("[^\\d]", "");
        return Pattern.matches(BASIC_PATTERN, cleanPhone);
    }
    
    public static String getOperator(String phone) {
        String cleanPhone = phone.replaceAll("[^\\d]", "");
        
        // 移动号段
        if (cleanPhone.matches("^(134[0-8]|135|136|137|138|139|147|148|150|151|152|157|158|159|172|178|182|183|184|187|188|195|197|198).*")) {
            return "中国移动";
        }
        // 联通号段
        else if (cleanPhone.matches("^(130|131|132|145|146|155|156|166|167|171|175|176|185|186|196).*")) {
            return "中国联通";
        }
        // 电信号段
        else if (cleanPhone.matches("^(133|149|153|173|177|180|181|189|190|191|193|199).*")) {
            return "中国电信";
        }
        
        return "未知运营商";
    }
    

}